home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / sysprof3.zip / SYS_PROF.ASM < prev    next >
Assembly Source File  |  1989-06-20  |  33KB  |  815 lines

  1. ;-----------------------------------------------------------------------------;
  2. ;                                                                             ;
  3. ;                                  Listing 1                                  ;
  4. ;                                                                             ;
  5. ;   NAME : SYS_PROF                                                           ;
  6. ;                                                                             ;
  7. ;   DATE : March 24, 1988                                                     ;
  8. ;                                                                             ;
  9. ;   AUTHOR : (C) Copyright 1988 G. Kent Cobb - All Rights Reserved            ;
  10. ;                                                                             ;
  11. ;   DESCRIPTION :                                                             ;
  12. ;       This is the terminate-and-stay-resident portion of a system profiler. ;
  13. ;       It installs several interrupt handlers, which monitor the occurrences ;
  14. ;       and duration of a number of software interrupts.                      ;
  15. ;                                                                             ;
  16. ;-----------------------------------------------------------------------------;
  17. ;   Updated count of interrupt functions by Ralf Brown, 5/18/89               ;
  18. ;-----------------------------------------------------------------------------;
  19. ;   More interrupts, speed ups, by Ralf Brown 6/18/89                         ;
  20. ;-----------------------------------------------------------------------------;
  21. ;   Fixed minor bug introduced 6/18, more speed tweaks on 6/20/89             ;
  22. ;-----------------------------------------------------------------------------;
  23.  
  24. ;----------------------------------------------------------------------------;
  25. ;                              Interrupt numbers                             ;
  26. ;----------------------------------------------------------------------------;
  27.  
  28. TIMER_INTERRUPT     EQU 1CH
  29. TERMINATE           EQU 20H
  30. TERM_AND_STAY_RES   EQU 27H
  31. CONTROL_INTERRUPT   EQU 60H
  32.  
  33. ;----------------------------------------------------------------------------;
  34. ;                  MS-DOS functions (Interrupt 21H services)                 ;
  35. ;----------------------------------------------------------------------------;
  36.  
  37. DOS MACRO   OP
  38.     MOV AH,DOS_&OP
  39.     INT 21H
  40.     ENDM
  41.  
  42. DOS_DISPLAY_STRING  EQU 09H
  43. DOS_SET_INT_VECTOR  EQU 25H
  44. DOS_GET_INT_VECTOR  EQU 35H
  45.  
  46. ;----------------------------------------------------------------------------;
  47. ;   This is a list of all the interrupts that are intercepted by SYS_PROF.   ;
  48. ;----------------------------------------------------------------------------;
  49.  
  50. NUMBER_OF_INTERRUPTS        EQU 13
  51.  
  52. PRINT_SCREEN_INTERRUPT      EQU  5H
  53. VIDEO_INTERRUPT             EQU 10H
  54. DISK_INTERRUPT              EQU 13H
  55. COMM_INTERRUPT              EQU 14H
  56. SYS_UTIL_INTERRUPT          EQU 15H
  57. KEYBOARD_INTERRUPT          EQU 16H
  58. PRINTER_INTERRUPT           EQU 17H
  59. DOS_FUNC_INTERRUPT          EQU 21H
  60. ABS_DISK_READ_INTERRUPT     EQU 25H
  61. ABS_DISK_WRITE_INTERRUPT    EQU 26H
  62. NETWORK2A_INTERRUPT         EQU 2AH
  63. MULTIPLEX_INTERRUPT         EQU 2FH
  64. EMS_INTERRUPT               EQU 67H
  65.  
  66. ;----------------------------------------------------------------------------;
  67. ;   These are the number of distinct services defined for each interrupt.    ;
  68. ;   The OCCURRENCES array contains two double words for each service, and    ;
  69. ;   two additional double words for each interrupt.  If an interrupt is      ;
  70. ;   generated with a service number that is out of range, the data for it    ;
  71. ;   will accumulate in this additional bin.                                  ;
  72. ;----------------------------------------------------------------------------;
  73.  
  74. PRINT_SCREEN_SERVICES       EQU 0
  75. VIDEO_SERVICES              EQU 29
  76. DISK_SERVICES               EQU 29
  77. COMM_SERVICES               EQU 6
  78. SYS_UTIL_SERVICES           EQU 223
  79. KEYBOARD_SERVICES           EQU 19
  80. PRINTER_SERVICES            EQU 3
  81. DOS_FUNC_SERVICES           EQU 109
  82. ABS_DISK_READ_SERVICES      EQU 0
  83. ABS_DISK_WRITE_SERVICES     EQU 0
  84. NETWORK2A_SERVICES          EQU 7
  85. MULTIPLEX_SERVICES          EQU 206
  86. EMS_SERVICES                EQU 108
  87.  
  88. ;-----------------------------------------------------------------------;
  89. ;   This macro defines the handling of the intercepted interrupts.  The ;
  90. ;   INT_NUM parameter that the macro expects is an index into the       ;
  91. ;   MAX_SERVICES and OFFSETS tables.                                    ;
  92. ;                                                                       ;
  93. ;   Interrupts 25H and 26H are handled in a manner which is very        ;
  94. ;   similar, but slightly different from the other interrupts.  If this ;
  95. ;   macro is invoked with a second parameter, code is included to       ;
  96. ;   provide the special handling that these interrupts require.         ;
  97. ;                                                                       ;
  98. ;   INT 15h requires that the stack be undisturbed on entry to the      ;
  99. ;   original ISR, as parameters are passed on the stack for DESQview    ;
  100. ;   At this time, SPECIAL and STACK_PARMS are mutually exclusive (the   ;
  101. ;   stack restoration code won't work for SPECIAL)                      ;
  102. ;-----------------------------------------------------------------------;
  103.  
  104. PERFORM_INTERRUPT MACRO INT_NUM,MAX_SERV,SPECIAL,STACK_PARMS
  105.  
  106. IFNB <STACK_PARMS>
  107. PRIVATE&INT_NUM  DW  80 DUP (?)  ; enough for 15 recursive invocations of ISR
  108. TOP_PRIVATE&INT_NUM LABEL WORD
  109. PRIVATE_TOP&INT_NUM DW TOP_PRIVATE&INT_NUM
  110. ENDIF
  111.  
  112. INTERRUPT_HANDLER&INT_NUM   PROC    FAR
  113.  
  114. ;   Turn interrupts back on.
  115.  
  116.         STI
  117.  
  118. ;   Save the existing interrupt and service numbers on the stack.
  119.  
  120.         PUSH CS:WORD PTR INTERRUPT
  121.  
  122. ;   Push the flags onto the stack now (before we execute any instructions which
  123. ;   might change them) in order to simulate an interrupt later. 
  124.  
  125.         PUSHF
  126.  
  127. ;   If accumulation is turned off, go straight to the real ISR.
  128.  
  129.         CMP  WORD PTR CS:WATCH,0
  130.         JE   READY_FOR_INTERRUPT&INT_NUM
  131.  
  132. ;   Make sure the service number is valid, then turn off interrupts briefly
  133. ;   while setting new INTERRUPT and SERVICE values
  134.  
  135.         PUSH AX
  136.         PUSH BX                    ; push registers
  137.  
  138.         CMP  AH,MAX_SERV           ; Compare current service number to max
  139.         JB   SERVICE_VALID&INT_NUM ; If less, everything is OK
  140.         MOV  AH,MAX_SERV           ; Otherwise, set the service to the maximum #
  141. SERVICE_VALID&INT_NUM:
  142.         CLI
  143.         MOV  CS:INTERRUPT,&INT_NUM ; must be updated for INT 1Ch handler to
  144.         MOV  CS:SERVICE,AH         ; update proper service counter
  145.         STI
  146.  
  147. ;   now increment the second bin for the service
  148.         MOV  BX,CS:OFFSETS[(&INT_NUM*2)]  ; Get the offset into the accumulation table
  149.         MOV  AL,AH              ; move code for service currently being
  150.                                 ;   performed into al
  151.         XOR  AH,AH              ; zero out ah
  152.         SHL  AX,1               ; multiply by 4 to convert number of 
  153.         SHL  AX,1               ;   double words to number of bytes
  154.         SHL  AX,1               ; multiply by 2 since there are two double 
  155.                                 ;   words for each service
  156.         ADD  BX,AX              ; add offset to get offset of data for this
  157.                                 ;   service
  158.         ADD  CS:WORD PTR [BX+4],1 ; Increment low-order word of second bin
  159.         ADC  CS:WORD PTR [BX+6],0 ; if overflow, incr high-order word also
  160.  
  161.         POP  BX                 ; Restore registers
  162.         POP  AX
  163.  
  164. READY_FOR_INTERRUPT&INT_NUM:
  165.  
  166. ;   After tabulating occurrence data, execute the real ISR
  167. IFNB <STACK_PARMS>
  168.         POPF
  169.         PUSH BX
  170.         MOV  BX,CS:PRIVATE_TOP&INT_NUM
  171.         SUB  BX,10                  ; will use five words on the private stack
  172.         MOV  CS:PRIVATE_TOP&INT_NUM,BX
  173.         POP  CS:[BX]                ; remove BX from stack
  174.         POP  CS:[BX+2]              ; remove INTERRUPT
  175.